﻿CREATE VIEW dbo.resuma_StatDeFunctii0
AS
SELECT     dbo.Persoane.NumePrenume AS Nume, dbo.Ocupatii.Denumire AS Functia, 
                      CASE WHEN dbo.TipStudii.Descriere = 'Superioare' THEN 'S' WHEN dbo.TipStudii.Descriere = 'Generale' THEN 'G' WHEN dbo.TipStudii.Descriere = 'Medii' THEN 'M' WHEN
                       dbo.TipStudii.Descriere = 'Post liceale' THEN 'PL' WHEN dbo.TipStudii.Descriere = 'Superioare de scurta durata' THEN 'SSD' END AS Nivel_Studii, 
                      AngS.DeLaData AS DeLaDataSalarizare, AngS.Salar AS Sal_Func, AngS.FractiuneNorma AS Cuantum_post, COALESCE (dbo.Departamente.Nume, '') AS Den_LocM, 
                      sp.DataObtinere AS DataObtinereSpecialitate, dbo.TipSpecialitati.Denumire AS Spec, dbo.AngajatiOcupatii.DeLaData AS DeLaDataOcupatie, 
                      dbo.AngajatiOcupatii.PanaLaData AS PanaLaDataOcupatie, COALESCE (dbo.Departamente.NumericField, 0) AS Nr_Paturi, asp.spv, asp.lei_spv, asp.lei_cond, 
                      asp.cond, asp.lei_merit, asp.merit, sp.Principala, dbo.Departamente.IDDepartament AS Cod_LM, dbo.Ocupatii.IDOcupatie AS Cod_Func, 
                      dbo.Persoane.DataPlecarii
FROM         dbo.Persoane LEFT OUTER JOIN
                      dbo.AngajatiOcupatii ON dbo.Persoane.IdPersoana = dbo.AngajatiOcupatii.IDPersoana INNER JOIN
                      dbo.Ocupatii ON dbo.AngajatiOcupatii.IDOcupatie = dbo.Ocupatii.IDOcupatie INNER JOIN
                      dbo.TipStudii ON dbo.Persoane.IdTipStudii = dbo.TipStudii.IdTipStudii INNER JOIN
                      dbo.AngajatiSalarizare AS AngS ON dbo.Persoane.IdPersoana = AngS.IdPersoana INNER JOIN
                      dbo.Departamente ON AngS.IDDepartament = dbo.Departamente.IDDepartament LEFT OUTER JOIN
                      dbo.SpecialitatiPersoane AS sp ON dbo.Persoane.IdPersoana = sp.IdPersoana LEFT OUTER JOIN
                      dbo.TipSpecialitati ON sp.IDSpecialitate = dbo.TipSpecialitati.IdSpecialitate LEFT OUTER JOIN
                          (SELECT     a.IdPersoana, MAX(a.Procent) AS spv, MAX(a.Valoare) AS lei_spv, MAX(COALESCE (b.Procent, 0)) AS cond, MAX(COALESCE (b.Valoare, 0)) AS lei_cond, 
                                                   MAX(COALESCE (c.Procent, 0)) AS merit, MAX(COALESCE (c.Valoare, 0)) AS lei_merit
                            FROM          dbo.AngajatiSporuri AS a LEFT OUTER JOIN
                                                   dbo.AngajatiSporuri AS b ON a.IdPersoana = b.IdPersoana AND COALESCE (b.IdTipSpor, 0) IN (21, 0) LEFT OUTER JOIN
                                                   dbo.AngajatiSporuri AS c ON a.IdPersoana = c.IdPersoana AND COALESCE (c.IdTipSpor, 0) IN (30, 0)
                            WHERE      (COALESCE (a.IdTipSpor, 0) IN (1, 0))
                            GROUP BY a.IdPersoana) AS asp ON asp.IdPersoana = dbo.Persoane.IdPersoana
WHERE     (dbo.AngajatiOcupatii.DeLaData =
                          (SELECT     MAX(DeLaData) AS Expr1
                            FROM          dbo.AngajatiOcupatii AS a
                            WHERE      (IDPersoana = dbo.AngajatiOcupatii.IDPersoana))) AND (sp.Principala = 1) OR
                      (sp.Principala IS NULL) AND (AngS.NormaBaza = 1)
GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPaneCount', @value = 2, @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'resuma_StatDeFunctii0';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane2', @value = N'ags = 280
            TopColumn = 0
         End
         Begin Table = "TipSpecialitati"
            Begin Extent = 
               Top = 366
               Left = 38
               Bottom = 455
               Right = 198
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "asp"
            Begin Extent = 
               Top = 6
               Left = 482
               Bottom = 125
               Right = 642
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'resuma_StatDeFunctii0';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane1', @value = N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "Persoane"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 125
               Right = 225
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "AngajatiOcupatii"
            Begin Extent = 
               Top = 6
               Left = 263
               Bottom = 125
               Right = 444
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Ocupatii"
            Begin Extent = 
               Top = 126
               Left = 38
               Bottom = 245
               Right = 215
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "TipStudii"
            Begin Extent = 
               Top = 126
               Left = 253
               Bottom = 230
               Right = 413
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "AngS"
            Begin Extent = 
               Top = 234
               Left = 253
               Bottom = 353
               Right = 438
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Departamente"
            Begin Extent = 
               Top = 246
               Left = 38
               Bottom = 365
               Right = 215
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "sp"
            Begin Extent = 
               Top = 354
               Left = 253
               Bottom = 473
               Right = 429
            End
            DisplayFl', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'resuma_StatDeFunctii0';

